const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const app = getApp();
let that;
Page({
  data: {
    ImgRootUrl: app.globalData.ImgRootUrl,
    brandList: [],
    page: 1,  //页码
    size: 10, //单页条数
    totalPages: 1   //总页数
  },
  onLoad: function (options) {
    that = this;
    // 页面初始化 options为页面跳转所带来的参数
    this.getBrandList();
  },
  //获取品牌列表
  getBrandList: function () {
    util.request(api.BrandList, { page: that.data.page, size: that.data.size }).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          brandList: that.data.brandList.concat(res.data.BrandList),
          totalPages: res.data.totalPages
        });
      }
    });
  },
  //上拉触底函数，加载更多
  onReachBottom (){
    if (this.data.totalPages > this.data.page) {
      this.setData({
        page: this.data.page + 1
      });
    } else {
      return false;
    }
    this.getBrandList();
  },
  onReady: function () {
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})